﻿<UserControl x:Class="WpfImageDuplicates.ImageCollectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:y="clr-namespace:WpfImageDuplicates"
             xmlns:local="clr-namespace:WpfImageDuplicates"
             xmlns:dragdrop="clr-namespace:DragDropLibrary;assembly=DragAndDrop"
             xmlns:ui="clr-namespace:VirtualizingTilePanelSample"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"          
             dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"    
             mc:Ignorable="d" SizeChanged="UserControl_SizeChanged" PreviewMouseLeftButtonDown="gridMain_PreviewMouseLeftButtonDown">
    <Grid x:Name="gridMain">
        <Grid Background="White" Visibility="Collapsed" x:Name="imgView" Canvas.ZIndex="99" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Border BorderBrush="Black" BorderThickness="6" Padding="8,8,8,8">
                <Image x:Name="testImage" Width="200" Stretch="Uniform"/>
            </Border>
        </Grid>

        <Grid Canvas.ZIndex="100" HorizontalAlignment="Right" VerticalAlignment="Top" x:Name="mouseGrid" Background="LightCyan">
            <TextBlock Text="{Binding DisplayCoords}"/>
        </Grid>

        <!--dragdrop:DragAndDrop.DragEnabled="true"-->
        <ListBox Grid.Row="0" Name="lstItems" SelectionMode="Extended" KeyDown="lstItems_KeyDown" HorizontalAlignment="Stretch" Focusable="False" VerticalAlignment="Stretch"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" Padding="0,0,0,0"                      
                 dragdrop:DragAndDrop.RegisterDragSourceName="ImageCollectionView" 
                 dragdrop:DragAndDrop.RegisterDropTargetName="ThumbnailListView"
                 dragdrop:DragAndDrop.DropMethodName="DropOntoImageCollectionView"    
                 dragdrop:DragAndDrop.DropEnabled="True"                                                         
                 SelectionChanged="lstItems_SelectionChanged" 
                 ScrollViewer.CanContentScroll="True"                                                    
             >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <ui:VirtualizingTilePanel KeyDown="WrapPanel_KeyDown" Loaded="itemsPanel_Loaded" Margin="0"
                                              ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border x:Name="sizeBorder" Cursor="SizeNWSE" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="3" BorderBrush="Transparent" Padding="0" Margin="0">
                        <Grid Tag="{Binding}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Cursor="Arrow" Margin="0">
                            <local:ThumbnailView x:Name="thumbView" FileImageViewModel="{Binding}" 
                                                 BorderThickness="1" Padding="0" Margin="1" BorderBrush="Black" Foreground="Black"
                                                 Width="{Binding Mode=OneWay, Path=CurrentSettings.ThumbWidth}"
                                                 Height="{Binding Mode=OneWay, Path=CurrentSettings.ThumbHeight}"
                                                 ThumbVisibilityChanged="thumbView_ThumbVisibilityChanged"
                                                 SetThumbImage="thumbView_SetThumbImage"
                                                 Tag="{Binding}" Loaded="thumbView_Loaded"/>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Grid x:Name="loadingGrid" HorizontalAlignment="Center" VerticalAlignment="Center">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Text="Loading " FontSize="18"/>
                <TextBlock Text="{Binding Count}" FontSize="18"/>
                <TextBlock Text=" Images..." FontSize="18"/>
            </StackPanel>
        </Grid>
    </Grid>
</UserControl>
